package cn.edu.nju.software.action.comment;

import java.util.ArrayList;
import java.util.List;

import cn.edu.nju.software.bean.show.CommentSearchListItem;
import cn.edu.nju.software.bean.show.CommentShow;
import cn.edu.nju.software.bean.show.UserShow;
import cn.edu.nju.software.service.intf.CommentService;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class GetBookCommentsAction extends ActionSupport {

	private int bookID;
	private List<CommentShow> commentShows;
	private CommentService commentService;

	public void setBookID(int bookID) {
		this.bookID = bookID;
	}

	public int getBookID() {
		return bookID;
	}

	public List<CommentShow> getCommentShows() {
		return commentShows;
	}

	public void setCommentService(CommentService commentService) {
		this.commentService = commentService;
	}
	
	@Override
	public String execute() throws Exception {
		List<CommentSearchListItem> commentItems = commentService.getCommentByBookID(bookID);
		commentShows = new ArrayList<CommentShow>(commentItems.size());
		for (CommentSearchListItem commentItem : commentItems) {
			UserShow user = new UserShow(commentItem.getUserName());
			commentShows.add(new CommentShow(commentItem.getComment(), user, null));
		}
		commentItems = null;
		return SUCCESS;
	}
	
}
